package com.zlc.common.core.process.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zlc.common.common.service.BaseServiceImpl;
import com.zlc.common.core.process.model.entity.StoneNodeApproveConfig;
import com.zlc.common.core.process.model.entity.StoneNodeApproveUserConfig;
import com.zlc.common.core.process.mapper.StoneNodeApproveUserConfigMapper;
import com.zlc.common.core.process.model.vo.StoneNodeApproveConfigVo;
import com.zlc.common.core.process.model.vo.StoneNodeApproveUserConfigVo;
import com.zlc.common.core.process.service.StoneNodeApproveUserConfigService;
import com.zlc.common.core.user.model.vo.MayanPlatUserVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author  zl
 * @date 2023-10-17 
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class StoneNodeApproveUserConfigServiceImpl extends BaseServiceImpl<StoneNodeApproveUserConfigMapper, StoneNodeApproveUserConfig, StoneNodeApproveUserConfigVo> implements StoneNodeApproveUserConfigService{
    @Override
    public void removeByProcessId(String processId) {
        LambdaQueryWrapper<StoneNodeApproveUserConfig> wrapper = wrapper()
                .eq(StoneNodeApproveUserConfig::getProcessId, processId);
        List<StoneNodeApproveUserConfigVo> nodeVos = queryVoList(wrapper);
        if(!ObjectUtils.isEmpty(nodeVos)){
            List<String> ids = nodeVos.stream().map(StoneNodeApproveUserConfigVo::getId).collect(Collectors.toList());
            deleteObjByIds(ids);
        }
    }

    @Override
    public List<StoneNodeApproveUserConfigVo> getByProcessId(String processId) {
        LambdaQueryWrapper<StoneNodeApproveUserConfig> wrapper = wrapper()
                .eq(StoneNodeApproveUserConfig::getProcessId, processId);
        return queryVoList(wrapper);
    }

    @Override
    public List<StoneNodeApproveUserConfigVo> getByConfigId(String configId) {
        LambdaQueryWrapper<StoneNodeApproveUserConfig> userWrapper = wrapper()
                .eq(StoneNodeApproveUserConfig::getConfigId, configId)
                .orderByAsc(StoneNodeApproveUserConfig::getOrder);
        return queryVoList(userWrapper);
    }

    @Override
    public List<StoneNodeApproveUserConfigVo> getByEventId(String eventId) {
        LambdaQueryWrapper<StoneNodeApproveUserConfig> userWrapper = wrapper()
                .eq(StoneNodeApproveUserConfig::getEventId, eventId)
                .orderByAsc(StoneNodeApproveUserConfig::getOrder);
        return queryVoList(userWrapper);
    }

}
